" Vunlde 插件管理器
source ~/auto/vundle_plugin.vim

" 在处理未保存或只读文件的时候，弹出确认
set confirm

" 不要使用vi的键盘模式，而是vim自己的
set nocompatible

" history文件中需要记录的行数
set history=500

set report=0

" 高亮显示匹配括号
set showmatch

" 正在被搜索的词句高亮显示
set hlsearch

" 正在被搜索的词句不高亮显示
"set nohlsearch

" 搜索输入时逐字符高亮显示和查找
set incsearch

set nonumber
set ruler
set showcmd
set tags+=~/.systag

"set nocompatible
filetype plugin indent on

set ts=4            " tabstop
set sw=4            " shiftwidth
set et              " expandtab tab自动转换空格
autocmd FileType c,cpp set sw=4 | set ts=4 | set et

set encoding=utf-8 fileencodings=ucs-bom,utf-8,cp936

set autoindent
set cindent
set cino=:0g0t0(sus " C/C++风格缩进选项: switch/case对齐, public/private不缩进, 函数返回类型单行不缩进等
                    " (sus 当一对括号跨越多行时，其后的行缩进前面 sw 指定的距离

set laststatus=2 " 总是显示状态栏
"set mouse=a      " 此开关当用鼠标选择时不选择行号, 关闭该项mouse=
"set cursorline   " 设置光标行标识后，下划线'_'会导致在当前光标行中不能明显识别！
"hi CursorLine   cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white
"hi CursorLine  cterm=bold ctermbg=0
"highlight StatusLine cterm=italic ctermfg=10 ctermbg=4
""highlight StatusLine cterm=none ctermfg=10 ctermbg=4
"highlight statusline term=bold ctermbg=5 guibg=DarkMagenta
set foldmethod=syntax
" set foldcolumn=6
syntax on
set foldlevel=99 "缩写fdl,默认展开折叠内容,既默认开启了zR


" map <F6> <Esc>:1,$g/^[  ]*$/d<CR><Esc> " 删除空白行，包括 空格和 tab键 的空行
" map <F6> <Esc>:1,$g/^$/d<CR><Esc> 		" 删除空行

" null line delete
"cmap nld 	<esc>:1,$g/^$/d<CR><esc>
"imap nld<cr> <esc>:1,$g/^$/d<CR><esc>
map dnl 	<esc>:1,$g/^$/d<CR><esc>

function Del()
	execute dnl
endfunction

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 快捷设置查找高亮开关
" s + 回车
map s<cr>  :set hlsearch
map s<esc> :set nohlsearch

" 手工折叠
nmap fm<cr> :set foldmethod=manual<cr>
" 标记折叠
nmap fs<cr> :set foldmethod=syntax<cr>

" 删除行末空白符
nmap sd<cr> :%s/\s\+$//<cr>
vmap sd<cr> :s/\s\+$//<cr>
" 删除空白行
nmap sg<cr> :g/^\s*$/d<cr>
vmap sg<cr> :g/^\s*$/d<cr>


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" Insert standard header according to the file name
" for example:
"   #ifndef _SOME_H_
"   #define _SOME_H_
"
"   #endif  /* _SOME_H_ */
" Usage:
"   :AddHdr     /* or */
"   :call AddH()
:command -nargs=* AddH call AddH(<f-args>)
function AddH()
	"let hdr = printf("__YH_%s__", toupper(tr(bufname("%"), ".", "_")))
  " 取文件名(含PATH)转换为宏, /和.都转换为_
	let hdr = printf("__YH_%s__", toupper(tr(tr(bufname("%"), ".", "_"), "/", "_")))
	call append("0", "#ifndef " . hdr)
	call append("1", "#define " . hdr)
	call append("2", "")
	call append("3", "")
	call append("4", "#ifdef __cplusplus")
	call append("5", "extern \"C\"")
	call append("6", "{")
	call append("7", "#endif")
	call append("8", "")
	call append("9", "#pragma pack(push)")
	call append("10", "#pragma pack(1)")
	call append("11", "#pragma pack(pop)")
	call append("12", "")
	call append("13", "")
	call append("$", "")
	call append("$", "")
	call append("$", "#ifdef __cplusplus")
	call append("$", "}")
	call append("$", "#endif")
	call append("$", "#endif /* " . hdr . " */")
endfunction


" comment(//) or uncomment your selected(under visual mode) lines
vmap <silent> // :!sed 's/^/\/\//'<CR>
vmap <silent> \\ :!sed 's/^\/\///'<CR>

" comment(#) or uncomment your select (use visual mode) lines
vmap <silent> #  :!sed 's/^/\#/'<CR>
vmap <silent> \# :!sed 's/^\#//'<CR>

" comment(/*  */) or uncomment your selected(under visual mode) lines
vmap <silent> /* <Esc><Esc>:'< !sed 's/^/\/* /'<Esc>:'> !sed 's/$/ *\//'<CR>
vmap <silent> \* <Esc><Esc>:'< !sed 's/^\/\* //'<Esc>:'> !sed 's/ \*\/$//'<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" 设置cscope快捷键
if has("cscope.out")
    cs add csope.out
elseif $CSCOPE_DB != ""
    cs add $CSCOPE_DB
endif
nmap <C-@>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>f :cs find f <C-R>=expand("<cword>")<CR><CR>
nmap <C-@>i :cs find i ^<C-R>=expand("<cword>")<CR>$<CR>
nmap <C-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>

" 让vim记忆上次编辑的位置
if has("autocmd")
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\   exe "normal g`\"" |
\ endif
endif
"------------------------

" 加载vimgdb按键映射
:command -nargs=* GDB call GDB(<f-args>)
function GDB()
    run macros/gdb_mappings.vim
endfunction
nmap g<CR>      <ESC>:GDB<CR>
imap <ESC>g<CR> <ESC>:GDB<CR>li

nmap <F1> <esc>:only<cr>
nmap <F2>      :cs kill 0<cr>:!cscope -Rbq<cr>:cs add cscope.out<CR>:!echo cscope has reconstruction<cr>
imap <F2> <ESC>:cs kill 0<cr>:!cscope -Rbq<cr>:cs add cscope.out<CR>:!echo cscope has reconstruction<cr>
" ctags 快捷生成
nmap <F3>      :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .; echo ctags has reconstruction<CR>
imap <F3> <ESC>:!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .; echo ctags has reconstruction<CR>
"nmap <F4> <esc>:Tlist<cr>
nmap <F4> <esc>:Tagbar<CR>
nmap <F5> :cp<cr>
nmap <F6> :cn<cr>
" <F7> vimgdb used, KeyMapConfig on-off
set pastetoggle=<F8>
set cscopequickfix=s-,c-,d-,i-,t-,e-,g-
nmap <F9>  <esc><c-w>10<
nmap <F10> <esc><c-w>10>
nmap <F11> <esc><c-w>10-
nmap <F12> <esc><c-w>10+
nmap <space> za
vmap <c-c> y

" 代码高亮开关键定义 Fangxm
" nmap <silent> <F12> :if exists("syntax_on") <Bar>
" 	\   syntax off <Bar>
" 	\ else <Bar>
" 	\   syntax on <Bar>
" 	\ endif <CR>

" vim 中执行 :make 调用的命令
set makeprg=clear&&make

let Tlist_Show_One_File=1               "不同时显示多个文件的tag，只显示当前文件的
let Tlist_WinWidth=30                   "设置taglist的宽度
let Tlist_Use_Right_Window=1            "在右侧窗口中显示taglist窗口
let Tlist_Exit_OnlyWindow=1             "如果taglist窗口是最后一个窗口，则退出vim

let godef_split=0                       "禁止godef的gd查找定义时split窗口

set backspace=2             " make backspace work like most other apps
set completeopt-=preview    " disable scratch preview window
"set backup                  " 文件保存时自动进行一次备份 file~

" 光标在窗口间移动
nmap <c-l> <c-w>l
nmap <c-h> <c-w>h
nmap <c-j> <c-w>j
nmap <c-k> <c-w>k
